/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cosc617_blackteam;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Anton
 * edited by Laura to add state
 */
class CustomerParty implements Iterable<Customer>{
	private I_CustomerState unseated;
	private I_CustomerState waitingForFood;
	private I_CustomerState waitingToPay;
	private I_CustomerState eating;
	private int timeToEat; //the time left before party is finished eating and can be removed
	
	private I_CustomerState state; //the state of the customer
	private ArrayList<Order> partyOrders; //a list of all the orders the party has made
    private ArrayList<Customer> customer; //customers in the party
    
    private final int BASE_TIME_TO_EAT = 20;
    int id;

    public CustomerParty(){
    	this(-1);
    }
    public CustomerParty(int id) {
        this.customer = new ArrayList<>();
        state = new StateUnseated(this);
        unseated = new StateUnseated(this);
       waitingForFood = new StateWaitingForFood(this);
       waitingToPay = new StateWaitingToPay(this);
        eating = new StateEating(this);
       partyOrders = new ArrayList<Order>();
       calculateTimeToEat(); //can be changed or randomly created
       this.id = id;
    }

    public void addCustomer(Customer customer) {
        this.customer.add(customer);
        calculateTimeToEat();
        // don't know when we are finished adding customers so have to do this each time
    }
    
    public int getID(){
    	return id;
    }

    public int getSize() {
        return this.customer.size();
    }
    
    public void addOrder(Order order){
    	if(order != null)
    		partyOrders.add(order);
    }
    
    public ArrayList<Order> getPartyOrders(){
    	return partyOrders;
    }
    /**
     * @return if all of the parties orders are ready
     */
    public boolean allFoodIsReady(){
    	for (Order order : partyOrders){
    		if(!order.isReady())
    			return false;
    	}
    	return true;
    	
    }
    
    private void calculateTimeToEat(){
    	timeToEat = BASE_TIME_TO_EAT + getSize(); //larger parties take more time to eat
    }
    
    public int getTimeToEat(){
    	return timeToEat;
    }
    /**
     * Should only be called by state.doEating();
     */
    public void decrimentTimeToEat(){
    	timeToEat --;
    }
    
    public boolean needsSeating(){
    	return state.needsSeating();
    }
    public void assignToTable(){
    	state.assignToTable();
    }
    
    public void deliverFood(){
    	state.deliverFood();
    }

    public void doEating(){
    	state.decrimentTimeToEat();
    }
    
    public boolean unseatCustomer(){
    	return state.unseatCustomer();
    }
    
    public I_CustomerState getStateEating(){
    	return eating;
    }
    public I_CustomerState getStateUnseated(){
    	return unseated;
    }
    public I_CustomerState getStateWaitingForFood(){
    	return waitingForFood;
    }
    public I_CustomerState getStateWaitingToPay(){
    	return waitingToPay;
    }
    public void setState(I_CustomerState state){
    	this.state = state;
    }

 /*   public I_PersonIterator getCustomerIterator() {
        return new PersonIterator((I_Person)customer);
    }*/

	@Override
	public Iterator<Customer> iterator() {
		// TODO Auto-generated method stub
		return new DefaultCustomerIterator(customer);
	}
	public String toString(){
		return "Number in party: " + customer.size(); 
	}
}
